#ifndef SHOGISTATE_H_INCLUDED
#define SHOGISTATE_H_INCLUDED

#include <QtCore> 

#include "../common/shogicommand.h"
#include "../common/shogicommandmap.h"
#include "../common/shogitracker.h"
#include "../common/shogidef.h"


class HandshakeTracker : public StateTracker
{
public:
	HandshakeTracker() : StateTracker()
	{
		setFlag("client_version_ok",false);
		setFlag("username_ok",false);
		setFlag("password_validated",false);
		setFlag("handshake_completed",false);
	}
};

class GameNegotiationTracker : public StateTracker
{
public:
	GameNegotiationTracker() : StateTracker()
	{
		setFlag("game_params_accepted",false);
		setFlag("gamenegotiation_completed",false);
	}
};

class ShogiState  : public QObject
{
	Q_OBJECT
signals:
	void signalReadyToSend(Player, ShogiCommand);	
	void signalStateChange(Player);
	void signalWaitingForOtherPlayer(Player);
	
public:
	ShogiState() :  m_gameState(INITIALISED) {}
	GameState getCurrentState() const { return m_gameState;	}
	GameNegotiationTracker getGameNegotiationTracker() { return m_gamenegotiation; }
	void changeState(GameState state);
	void setPlayerId(Player p) {m_playerid = p;	}
	bool processCommand(ShogiCommand cmd);

	ShogiError m_error;

protected:
	bool doHandshake(ShogiCommand cmd);
	bool doGameNegotation(ShogiCommand cmd);


	CommandCode findCommand(ShogiCommand cmd);
	
private:
	Player m_playerid;
	HandshakeTracker		m_handshake;
	GameNegotiationTracker	m_gamenegotiation;
	GameState m_gameState;

};

#endif // SHOGISTATE_H_INCLUDED






